; StockGo.nsi
;
; This script is based on example1.nsi, but it remember the directory,
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install example2.nsi into a directory that the user selects,

;--------------------------------
!include "LogicLib.nsh"

!include WordFunc.nsh
!insertmacro VersionCompare

;!include LogicLib.nsh

; MUI 1.67 compatible ------
!include "MUI.nsh"

; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"


;Name ".NET Product"
;--------------------------------
; The name of the installer
Name "StockGo"
Caption "StockGo Setup安装"
Icon "Stock_res\setup.ico"

; The file to write
OutFile "StockGo2.exe"

; The default installation directory,$PROGRAMFILES
InstallDir C:\StockGo2

; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\StockGo2" "Install_Dir"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

;--------------------------------

; Pages

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

Function .onInit
  Call GetDotNETVersion
  Pop $0
  ${If} $0 == "not found"
    MessageBox MB_OK|MB_ICONSTOP ".NET runtime library is not installed."
    Abort
  ${EndIf}

  StrCpy $0 $0 "" 1 # skip "v"

  ${VersionCompare} $0 "2.0" $1
  ${If} $1 == 2
    MessageBox MB_OK|MB_ICONSTOP ".NET runtime library v2.0 or newer is required. You have $0."
    Abort
  ${EndIf}
FunctionEnd

Function GetDotNETVersion
  Push $0
  Push $1

  System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1 ?u"
  StrCmp $1 "error" 0 +2
    StrCpy $0 "not found"

  Pop $1
  Exch $0
FunctionEnd


; The stuff to install
Section "StockGo (required)"

  SectionIn RO

CreateDirectory "$INSTDIR\binn"
CreateDirectory "$INSTDIR\binn\bitmap"
CreateDirectory "$INSTDIR\binn\Data"
CreateDirectory "$INSTDIR\binn\data\Account"
CreateDirectory "$INSTDIR\binn\data\historysh"
CreateDirectory "$INSTDIR\binn\data\historysz"
CreateDirectory "$INSTDIR\binn\data\indicator"
CreateDirectory "$INSTDIR\binn\data\SH"
CreateDirectory "$INSTDIR\binn\data\SH\f10"
CreateDirectory "$INSTDIR\binn\data\SZ"
CreateDirectory "$INSTDIR\binn\data\SZ\f10"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CreateDirectory "$INSTDIR\binn\Extract"
CreateDirectory "$INSTDIR\binn\Extract\Download"
CreateDirectory "$INSTDIR\binn\Extract\Download\Detail"
CreateDirectory "$INSTDIR\binn\Extract\SH"
CreateDirectory "$INSTDIR\binn\Extract\SZ"
CreateDirectory "$INSTDIR\binn\html"
CreateDirectory "$INSTDIR\binn\NEWS"
CreateDirectory "$INSTDIR\binn\NEWS\cj"
CreateDirectory "$INSTDIR\binn\NEWS\shanghai"
CreateDirectory "$INSTDIR\binn\NEWS\shenzhen"
CreateDirectory "$INSTDIR\binn\NEWS\财经报道"
CreateDirectory "$INSTDIR\binn\NEWS\上交所公告"
CreateDirectory "$INSTDIR\binn\NEWS\深交所公告"
CreateDirectory "$INSTDIR\binn\Setting"
CreateDirectory "$INSTDIR\binn\temp"

  ; Set output path to the installation directory.
  SetOutPath $INSTDIR

  ;SetOutPath $INSTDIR\binn
  ;File ..\binn\stockGo.exe

  ; Put file there
  ;File "example2.nsi"

  SetOutPath $INSTDIR\binn
  ;CopyFiles "setup\BigBill.ini" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\NetTS.dll" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\RealTimeHs.dat" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\Report.dat" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\reportError.txt" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\StockGo.exe" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\StockName.dat" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\transfered.dat" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\zlib.dll" "$INSTDIR\binn\" 0
  ;CopyFiles "setup\财务数据.fin" "$INSTDIR\binn\" 0
  ;;;;;;;;;;;;;
  File "setup\BigBill.ini"
  File "setup\NetTS.dll"
    File "setup\NetTS_Day.dll"
        File "setup\NetTS_Min5.dll"
        File "setup\NetTS_Report.dll"
  File "setup\SaveTjxg.dat"
    File "setup\buySellAdditional.dat"
  File "setup\RealTimeHs.dat"
  File "setup\Report.dat" 
  ;File "setup\reportError.txt" 
  File "setup\StockGo.exe" 
  File "setup\StockName.dat" 
  File "setup\transfered.dat" 
  File "setup\zlib.dll" 
  File "setup\财务数据.fin" 
  ;File "setup\*.*"
  ;debug dll
  ; ...........debug dll ...................
File "setup\Microsoft.VC90.DebugCRT.manifest"
File "setup\msvcm90d.dll"
File "setup\msvcp90d.dll"
File "setup\msvcr90d.dll"
; ......Microsoft.VC90.DebugMFC
File "setup\mfc90d.dll"
File "setup\mfc90ud.dll"
File "setup\mfcm90d.dll"
File "setup\mfcm90ud.dll"
File "setup\Microsoft.VC90.DebugMFC.manifest"
; ......Microsoft.MFC90CHS.DLL
File "setup\MFC90CHS.DLL"
; ...........debug dll ...................
	;debug dll
  SetOutPath $INSTDIR\binn\block
  File "setup\block\*.*"
  ;SetOutPath $INSTDIR\binn\dat
  ;don't copy ,no use
  ;File "setup\dat\*.*"
  SetOutPath $INSTDIR\binn\data
  File "setup\data\*.*"
  SetOutPath $INSTDIR\binn\data\Account
  File "setup\data\Account\13631464138.acc"
  SetOutPath $INSTDIR\binn\data\indicator
  ;File "setup\data\indicator\*.*"
  ;;;;;;;rem 拷贝历史数据
  SetOutPath $INSTDIR\binn\data\historysh
  ;File "setup\data\historysh\*.*"
  SetOutPath $INSTDIR\binn\data\historysz
  ;File "setup\data\historysz\*.*"
  ;;;;;;;rem 拷贝历史数据
  ;;;;;;;rem 拷贝历史数据
  SetOutPath $INSTDIR\binn\data\indicator
  ;File "setup\data\indicator\0.ext"
    File "setup\data\indicator\0.ifo"
  File "setup\data\indicator\1.ext"
    File "setup\data\indicator\1.ifo"
  File "setup\data\indicator\2.ext"
    File "setup\data\indicator\2.ifo"
  ;File "setup\data\indicator\3.ext"
    File "setup\data\indicator\3.ifo"
  ;;;;;;;rem 拷贝历史数据
  SetOutPath $INSTDIR\binn\data\SH
  File "setup\data\SH\*.*"
  ;File "setup\data\SH\daykline.dat"
  ;File "setup\data\SH\minutekline.dat"
  ;File "setup\data\SH\selfLINE.DAT"
  ;File "setup\data\SH\tick.dat"
  ;;;;;;;rem 拷贝历史数据
  ;;;;;;;rem 拷贝历史数据
  SetOutPath $INSTDIR\binn\data\SZ
  File "setup\data\SZ\daykline.dat"
  File "setup\data\SZ\minutekline.dat"
  File "setup\data\SZ\selfLINE.DAT"
  File "setup\data\SZ\tick.dat"
   ;;;;;;;rem 拷贝历史数据
  SetOutPath $INSTDIR\binn\data\SH\f10
  ;File "setup\data\SH\f10\*.*"
  SetOutPath $INSTDIR\binn\data\SZ\f10
  ;File "setup\data\SZ\f10\*.*"
  ;Extract
  SetOutPath $INSTDIR\binn\Extract\*.*
  ;File "setup\Extract\*.*"
   SetOutPath $INSTDIR\binn\Extract\Download\*.*
  ;File "setup\Extract\Download\*.*"
   SetOutPath $INSTDIR\binn\Extract\Download\Detail\*.*
  ;File "setup\Extract\Download\Detail\*.*"
   SetOutPath $INSTDIR\binn\Extract\SH\*.*
  ;File "setup\Extract\SH\*.*"
  SetOutPath $INSTDIR\binn\Extract\SZ\*.*
  ;File "setup\Extract\SZ\*.*"
  ;html
  SetOutPath $INSTDIR\binn\html\*.*
  ;File "setup\html\*.*"
  ;NEWS
  SetOutPath $INSTDIR\binn\NEWS\*.*
  ;File "setup\NEWS\*.*"
  SetOutPath $INSTDIR\binn\NEWS\cj\*.*
  ;File "setup\NEWS\cj\*.*"
    SetOutPath $INSTDIR\binn\NEWS\shanghai\*.*
  ;File "setup\NEWS\shanghai\*.*"
    SetOutPath $INSTDIR\binn\NEWS\shenzhen\*.*
  ;File "setup\NEWS\shenzhen\*.*"
    SetOutPath $INSTDIR\binn\NEWS\财经报道\*.*
  ;File "setup\NEWS\\财经报道\*.*"
    SetOutPath $INSTDIR\binn\NEWS\上交所公告\*.*
  ;File "setup\NEWS\上交所公告\*.*"
    SetOutPath $INSTDIR\binn\NEWS\深交所公告\*.*
  ;File "setup\NEWS\深交所公告\*.*"
  ;temp file only,remove it
  ;SetOutPath $INSTDIR\binn\mytemp
  ;File "setup\mytemp\*.*"
  SetOutPath $INSTDIR\binn\Setting
  ;File "setup\Setting\*.*"
  SetOutPath $INSTDIR\binn\temp
  ;File "setup\temp\*.*"
  SetOutPath $INSTDIR\binn



  ;SetOutPath $INSTDIR\binn
  ;CopyFiles "setup\stockgo.exe" "$INSTDIR\binn" 0
  ;CopyFiles "setup\*.*" "$INSTDIR\binn" 0
  ;SetOutPath $INSTDIR\binn\dat
  ;CopyFiles "setup\dat\*.*" "$INSTDIR\binn\dat\" 0
  ;SetOutPath $INSTDIR\binn\data
  ;CopyFiles "setup\data\SHSE.COD" "$INSTDIR\binn\data\" 0
  ;CopyFiles "setup\data\SZSE.COD" "$INSTDIR\binn\data\" 0
  ;CopyFiles "setup\mytemp\*.*" "$INSTDIR\binn\mytemp\" 0
  ;CopyFiles "setup\projects\*.*" "$INSTDIR\binn\projects\*.*" 0


  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\StockGo2 "Install_Dir" "$INSTDIR"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\StockGo2" "DisplayName" "StockGo2"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\StockGo2" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\StockGo2" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\StockGo2" "NoRepair" 1
  WriteUninstaller "uninstall.exe"

SectionEnd

;--------------------------------
;Section "Test CopyFiles"

  ;SectionIn 1 2 3

  ;CreateDirectory "$INSTDIR\binn"
  ;SetOutPath $INSTDIR\binn
  ;CopyFiles "binn\stockgo.exe" "$INSTDIR\binn" 0

;SectionEnd

; Optional section (can be disabled by the user)
Section "StockGo 快捷方式"

SectionIn RO

  CreateDirectory "$SMPROGRAMS\StockGo2"
  CreateShortcut "$SMPROGRAMS\StockGo2\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortcut "$SMPROGRAMS\StockGo2\StockGo.lnk" "$INSTDIR\binn\stockGo.exe" "" "$INSTDIR\binn\stockGo.exe" 0
  ;CreateShortcut "$SMPROGRAMS\StockGo\StockGo智能交易.lnk" "$INSTDIR\binn\stockGo.exe" "" "$INSTDIR\binn\stockGo.exe" 0

  ;DESKTOP
  CreateShortcut "$DESKTOP\股狗StockGo2.lnk" "$INSTDIR\binn\StockGo.exe"

  CreateDirectory "$INSTDIR\Shortcuts"
  CreateShortcut "$INSTDIR\Shortcuts\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortcut "$INSTDIR\Shortcuts\StockGo.lnk" "$INSTDIR\binn\stockGo.exe" "" "$INSTDIR\binn\stockGo.exe" 0
  ;CreateShortcut "$INSTDIR\Shortcuts\StockGo智能交易.lnk" "$INSTDIR\binn\stockGo.exe" "" "$INSTDIR\binn\stockGo.exe" 0

SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"

  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\StockGo2"
  DeleteRegKey HKLM SOFTWARE\StockGo2

  ; Remove files and uninstaller
  ;Delete $INSTDIR\example2.nsi
  Delete $INSTDIR\uninstall.exe

  ; Remove shortcuts, if any
  Delete "$DESKTOP\股狗StockGo2.lnk"
  Delete "$SMPROGRAMS\StockGo2\*.*"
    RMDir "$SMPROGRAMS\StockGo2"
  ;Shortcut
  Delete "$INSTDIR\Shortcuts\*.*"
  Delete "$INSTDIR\binn\*.*"
  Delete "$INSTDIR\*.*"
  Delete "$INSTDIR\binn\dat\*.*"
    ;---------------------------------
        Delete "$INSTDIR\binn\bitmap\*.*"
  ;---------------------------------
    Delete "$INSTDIR\binn\block\*.*"
  ;---------------------------------
  Delete "$INSTDIR\binn\data\*.*"
  Delete "$INSTDIR\binn\data\Account\*.*"
  Delete "$INSTDIR\binn\data\historysh\*.*"
  Delete "$INSTDIR\binn\data\historysz\*.*"
  Delete "$INSTDIR\binn\data\indicator\*.*"
  Delete "$INSTDIR\binn\data\SH\f10\*.*"
  Delete "$INSTDIR\binn\data\SZ\f10\*.*"
    Delete "$INSTDIR\binn\data\SH\*.*"
  Delete "$INSTDIR\binn\data\SZ\*.*"
    ;---------------------------------
  Delete "$INSTDIR\binn\Extract\Download\Detail\*.*"
  Delete "$INSTDIR\binn\Extract\Download\*.*"
  Delete "$INSTDIR\binn\Extract\SH\*.*"
  Delete "$INSTDIR\binn\Extract\SZ\*.*"
      ;---------------------------------
  Delete "$INSTDIR\binn\html\*.*"
        ;---------------------------------
  Delete "$INSTDIR\binn\NEWS\*.*"
    Delete "$INSTDIR\binn\NEWS\cj\*.*"
      Delete "$INSTDIR\binn\NEWS\shanghai\*.*"
        Delete "$INSTDIR\binn\NEWS\shenzhen\*.*"
  Delete "$INSTDIR\binn\NEWS\财经报道\*.*"
Delete "$INSTDIR\binn\NEWS\上交所公告\*.*"
   Delete "$INSTDIR\binn\NEWS\深交所公告\*.*"
   ;---------------------------------
  Delete "$INSTDIR\binn\Setting\*.*"
  Delete "$INSTDIR\binn\temp\*.*"

  ; Remove directories used
  ;RMDir "$SMPROGRAMS\StockGo\binn"
  RMDir "$SMPROGRAMS\StockGo2"
  RMDir "$INSTDIR\Shortcuts"
  ;RMDir "$INSTDIR\StockGo\binn"
  ;del start
  RMDir "$INSTDIR\binn\dat"
      ;---------------------------------
        RMDir "$INSTDIR\binn\bitmap"
    ;---------------------------------
    RMDir "$INSTDIR\binn\block"
  ;---------------------------------
  RMDir "$INSTDIR\binn\data\Account"
  RMDir "$INSTDIR\binn\data\historysh"
  RMDir "$INSTDIR\binn\data\historysz"
  RMDir "$INSTDIR\binn\data\indicator"
  RMDir "$INSTDIR\binn\data\SH\f10"
  RMDir "$INSTDIR\binn\data\SZ\f10"
    RMDir "$INSTDIR\binn\data\SH"
  RMDir "$INSTDIR\binn\data\SZ"
    RMDir "$INSTDIR\binn\data"
    ;---------------------------------
  RMDir "$INSTDIR\binn\Extract\Download\Detail"
  RMDir "$INSTDIR\binn\Extract\Download"
  RMDir "$INSTDIR\binn\Extract\SH"
  RMDir "$INSTDIR\binn\Extract\SZ"
    RMDir "$INSTDIR\binn\Extract"
      ;---------------------------------
  RMDir "$INSTDIR\binn\html"
        ;---------------------------------

    RMDir "$INSTDIR\binn\NEWS\cj"
      RMDir "$INSTDIR\binn\NEWS\shanghai"
        RMDir "$INSTDIR\binn\NEWS\shenzhen"
  RMDir "$INSTDIR\binn\NEWS\财经报道"
RMDir "$INSTDIR\binn\NEWS\上交所公告"
   RMDir "$INSTDIR\binn\NEWS\深交所公告"
     RMDir "$INSTDIR\binn\NEWS"
   ;---------------------------------
  RMDir "$INSTDIR\binn\Setting"
  RMDir "$INSTDIR\binn\temp"
  ;del end
  RMDir "$INSTDIR\binn"
  RMDir "$INSTDIR"

  IfFileExists "$INSTDIR" 0 NoErrorMsg
    MessageBox MB_OK "Note: $INSTDIR could not be removed!,please delete youslelf,thanks" IDOK 0 ; skipped if file doesn't exist
  NoErrorMsg:

SectionEnd
